package ro.grig.downscale;

import java.io.Serializable;

/**
 * @author grig
 *
 */
public class RainRecordTO implements Serializable, Comparable<RainRecordTO> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8123044003632521175L;
	/**
	 * Pozitia citita, linia
	 */
	int pozition;
	int year;
	int month;
	int day;
	int hour;
	double rain=0d;
	int count;
	double diferenta=0d;

	public int getHour() {
		return hour;
	}

	public void setHour(int hour) {
		this.hour = hour;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public double getRain() {
		return rain;
	}

	public void setRain(double rain) {
		this.rain = rain;
	}

	@Override
	public String toString() {
		return "RainRecordTO [year=" + year + ", month=" + month + ", day="
				+ day + ", hour=" + hour + ", rain=" + rain + "]";
	}

	public void add(RainRecordTO hourrec) {
		count++;
		rain += hourrec.rain;
	}

	public void initForDay(RainRecordTO hourrec) {
		this.year = hourrec.getYear();
		this.month = hourrec.getMonth();
		this.day = hourrec.day;
		count++;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	@Override
	public int compareTo(RainRecordTO o) {
		if (this.year < o.year) {
			return -1;
		} else if (this.year > o.year) {
			return 1;
		} else {
			if (this.month < o.month) {
				return -1;
			} else if (this.month > o.month) {
				return 1;
			} else {
				if (this.day < o.day) {
					return -1;
				} else if (this.day > o.day) {
					return 1;
				} else {
					if (this.hour < o.hour) {
						return -1;
					} else if (this.hour > o.hour) {
						return 1;
					} else {
						return 0;
					}
				}
			}
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + day;
		result = prime * result + hour;
		result = prime * result + month;
		result = prime * result + year;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RainRecordTO other = (RainRecordTO) obj;
		if (day != other.day)
			return false;
		if (hour != other.hour)
			return false;
		if (month != other.month)
			return false;
		if (year != other.year)
			return false;
		return true;
	}

	public int getPozition() {
		return pozition;
	}

	public void setPozition(int pozition) {
		this.pozition = pozition;
	}

	public double getDiferenta() {
		return diferenta;
	}

	public void setDiferenta(double diferenta) {
		this.diferenta = diferenta;
	}
}
